﻿using System.Collections.Generic;
using GodLesZ.Library;

namespace Grove.Server {

	public class LogoPrinter {
		private readonly List<string> mLines = new List<string>();
		private readonly string mLogoHeader;
		private readonly string mLogoFooter;

		public EConsoleColor TextColor {
			get;
			set;
		}

		public EConsoleColor PrefixColor {
			get;
			set;
		}

		public EConsoleColor SufixColor {
			get;
			set;
		}

		public string PrefixSign {
			get;
			set;
		}

		public string SufixSign {
			get;
			set;
		}


		public LogoPrinter(string prefix = "(", EConsoleColor colorPrefix = EConsoleColor.None, string sufix = ")", EConsoleColor colorSufix = EConsoleColor.None, EConsoleColor colorText = EConsoleColor.None) {
			mLogoHeader = "";
			mLogoFooter = "";

			SufixSign = sufix;
			PrefixSign = prefix;
			PrefixColor = colorPrefix;
			SufixColor = colorSufix;
			TextColor = colorText;
			mLines.Add(@" _____                      _____                          ");
			mLines.Add(@"|  __ \                    /  ___|                         ");
			mLines.Add(@"| |  \/_ __ _____   _____  \ `--.  ___ _ ____   _____ _ __ ");
			mLines.Add(@"| | __| '__/ _ \ \ / / _ \  `--. \/ _ \ '__\ \ / / _ \ '__|");
			mLines.Add(@"| |_\ \ | | (_) \ V /  __/_/\__/ /  __/ |   \ V /  __/ |   ");
			mLines.Add(@" \____/_|  \___/ \_/ \___(_)____/ \___|_|    \_/ \___|_|   ");
			mLines.Add(@"                                                           ");
			mLines.Add(@"                   by GodLesZ & ???                        ");

			int len = mLines[0].Length;
			mLogoHeader = "";
			for (var i = 0; i < len; i += 2) {
				mLogoHeader += "-=";
			}
			if (mLogoHeader.Length < len) {
				mLogoHeader += "-";
			} else if (mLogoHeader.Length > len) {
				mLogoHeader = mLogoHeader.Substring(0, len);
			}
			mLogoFooter = mLogoHeader;
		}


		public void Print() {
			// Header
			PrintColoredLine(mLogoHeader, PrefixColor);
			// Lines
			mLines.ForEach(line => PrintColoredLine(line, TextColor));
			// Footer
			PrintColoredLine(mLogoFooter, PrefixColor);
		}

		private void PrintColoredLine(string text, EConsoleColor color) {
			CConsole.Write(PrefixColor, PrefixSign);
			CConsole.Write(color, text);
			CConsole.WriteLine(SufixColor, SufixSign);
		}

	}

}